<?php

/**
 * Admin_Libraries_Controller_Action
 * @version    $Id: Action.php 01-08-2010
 * @file       Action.php
 *
 */
abstract class Blocks_Libraries_Controller_Action extends Zend_Controller_Action
{

    public function init()
    {
        parent::init();
    }

    /**
     *
     */
    public function showimageAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        $fileorginal = base64_decode($this->_request->getParam('filename'));
        $fileinfo = pathinfo($fileorginal);
        $file = ($fileinfo['extension']);
        $filename = base64_decode($this->_request->getParam('filename'));
        $path = base64_decode($this->_request->getParam('path'));
        if (!file_exists($path . DS . $filename)) {
            $filename = 'no_image.jpg';
            $file = "jpg";
        }
        try {
            switch (strtolower($file)) {
                case "jpeg":
                case "jpg":
                    $im = imagecreatefromjpeg($path . DS . $filename);
                    header('Content-Type: image/jpg');
                    imagejpeg($im);
                    imagedestroy($im);
                    break;
                case "png":
                    $im = imagecreatefrompng($path . DS . $filename);
                    header('Content-Type: image/png');
                    imagepng($im);
                    imagedestroy($im);
                    break;
                case "gif":
                    $im = imagecreatefromgif($path . DS . $filename);
                    header('Content-Type: image/gif');
                    imagegif($im);
                    imagedestroy($im);
                    break;
                case "bmp":
                    $im = imagecreatefromwbmp($path . DS . $filename);
                    header('Content-Type: image/bmp');
                    imagewbmp($im);
                    imagedestroy($im);
                    break;
            }
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    }

}